import socket

local_address = ('0.0.0.0', 8000)
server = socket.socket()
server.setblocking(False)
server.bind(local_address)
server.listen(1) # 只有mac才有用
# print(server.getsockname())

while True:

    while True:
        try:
            connect, raddr = server.accept() # 阻塞
            break
        except BlockingIOError:
            pass

    while True:
        while True:
            try:
                recv_data = connect.recv(1024) # 阻塞  程序主动向操作系统提出休眠  就是卡住了
                break
            except BlockingIOError:
                pass
        if recv_data:
            print('server..', recv_data.decode('utf8'))
            connect.send(recv_data) # 一收一发
        else:
            connect.close()
            break